nlp_architect.models.crossling_emb.WordTranslator

class nlp_architect.models.crossling_emb.WordTranslator(hparams, src_vec, tgt_vec, vocab_size)[source]

Main network which does cross-lingual embeddings training

__init__(hparams, src_vec, tgt_vec, vocab_size)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(hparams, src_vec, tgt_vec, vocab_size)

Initialize self.

apply_procrustes(sess, final_pairs)

Applies procrustes to W matrix for better mapping :param sess: Tensorflow Session :type sess: tf.session :param final_pairs: Array of pairs which are mutual neighbors :type final_pairs: ndarray

generate_xling_embed(sess, src_dict, …)

Generates cross lingual embeddings :param sess: Tensorflow session :type sess: tf.session

report_metrics(iters, n_words_proc, …)

Reports metrics of how training is going

run(sess, local_lr)

Runs whole GAN :param sess: Tensorflow Session :type sess: tf.session :param local_lr: Learning rate :type local_lr: float

run_discriminator(sess, local_lr)

Runs discriminator part of GAN :param sess: Tensorflow Session :type sess: tf.session :param local_lr: Learning rate :type local_lr: float

run_generator(sess, local_lr)

Runs generator part of GAN :param sess: Tensorflow Session :type sess: tf.session :param local_lr: Learning rate :type local_lr: float

save_model(save_model, sess)

Saves W in mapper as numpy array based on CSLS criterion :param save_model: Save model if True :type save_model: bool :param sess: Tensorflow Session :type sess: tf.session

set_lr(local_lr, drop_lr)

Drops learning rate based on CSLS criterion :param local_lr: Learning Rate :type local_lr: float :param drop_lr: Drop learning rate by 2 if True :type drop_lr: bool

apply_procrustes(sess, final_pairs)[source]

Applies procrustes to W matrix for better mapping :param sess: Tensorflow Session :type sess: tf.session :param final_pairs: Array of pairs which are mutual neighbors :type final_pairs: ndarray

generate_xling_embed(sess, src_dict, tgt_dict, tgt_vec)[source]

Generates cross lingual embeddings :param sess: Tensorflow session :type sess: tf.session

static report_metrics(iters, n_words_proc, disc_cost_acc, tic)[source]

Reports metrics of how training is going

run(sess, local_lr)[source]

Runs whole GAN :param sess: Tensorflow Session :type sess: tf.session :param local_lr: Learning rate :type local_lr: float

run_discriminator(sess, local_lr)[source]

Runs discriminator part of GAN :param sess: Tensorflow Session :type sess: tf.session :param local_lr: Learning rate :type local_lr: float

run_generator(sess, local_lr)[source]

Runs generator part of GAN :param sess: Tensorflow Session :type sess: tf.session :param local_lr: Learning rate :type local_lr: float

Returns

Returns number of words processed

save_model(save_model, sess)[source]

Saves W in mapper as numpy array based on CSLS criterion :param save_model: Save model if True :type save_model: bool :param sess: Tensorflow Session :type sess: tf.session

static set_lr(local_lr, drop_lr)[source]

Drops learning rate based on CSLS criterion :param local_lr: Learning Rate :type local_lr: float :param drop_lr: Drop learning rate by 2 if True :type drop_lr: bool